package com.partner.springsecurity;

import java.io.IOException;  
import java.util.Date;  
  




import javax.servlet.ServletException;  
import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;  
  




import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;  
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;  
import org.springframework.security.web.savedrequest.RequestCache;  

import com.partner.bean.sysright.TLoginlog;
import com.partner.frame.common.ConstantsMark;
import com.partner.service.sysright.SysLoginlogManagerService;
  
public class CustomSavedRequestAwareAuthenticationSuccessHandler extends  
        SavedRequestAwareAuthenticationSuccessHandler {  
	
	@Autowired
	private SysLoginlogManagerService sysLoginlogManagerService;
	
    @Override  
    public void onAuthenticationSuccess(HttpServletRequest request,  
            HttpServletResponse response, Authentication authentication)  
            throws ServletException, IOException {  
          
        //System.out.println("用户登录成功处理。。。。");  
   
        String userName = authentication.getName(); //用户名  
        String address =  request.getRemoteAddr();  //远程地址  
        
        //新增用户登录日志
        TLoginlog log = new TLoginlog();
        log.setContent(ConstantsMark.LOGINLOG_IN);
        log.setTime(new Date(System.currentTimeMillis()));
        log.setIp(address);
        log.setUsername(userName);
        sysLoginlogManagerService.insert(log);
        
        super.onAuthenticationSuccess(request, response, authentication);     
  
    }  
  
    @Override  
    public void setRequestCache(RequestCache requestCache) {  
          
        super.setRequestCache(requestCache);  
    }  
      
      
  
} 
